<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <template id="sub-component">
        <button @click="handleClick">给父传值</button>
    </template>

    <main id="app">
        <p>name: {{name}}</p>
        <p>age: {{age}}</p>
        <sub-component :fun="fun"></sub-component>
    </main>
</body>
<script src="../../vue.js"></script>
<script>
    Vue.component("sub-component",{
        template: "#sub-component",
        props: {
            fun: {
                type: Function,
                required: true
            }
        },
        methods: {
            handleClick() {
                console.log("点击")
               this.fun({name:"奉先",age: 35}) 
            }
        }
    })

    new Vue({
        el: "#app",
        data() {
            return {
                name: "",
                age: "",
                fun: param => {
                    console.log("收到参数：",param);
                    this.name = param.name;
                    this.age = param.age;
                }
            }
        },
    })
</script>

</html>